﻿window['TemplateEditor'] = { __namespace: true, __typeName: 'TemplateEditor'};

TemplateEditor.SelectTab = function(tabId, hiddenId, selected, unselected, selectedTabClassName, unselectedTabClassName)
{
  var tab = document.getElementById(tabId);
  
  if (tab)
  {
    if (tab.parentNode)
    {
      for (var tabIndex = 0; tabIndex < tab.parentNode.childNodes.length; tabIndex++)
      {
        if (tab.parentNode.childNodes[tabIndex] != tab)
        {
          if (tab.parentNode.childNodes[tabIndex].style)
          {
            tab.parentNode.childNodes[tabIndex].style.display = 'none';
          }
        }
      }
    }
    
    tab.style.display = 'block';
    
    var hidden = document.getElementById(hiddenId);
    
    if (hidden) hidden.value = tabId;
    
    TemplateEditor.SwitchTabClasses(selected, unselected, selectedTabClassName, unselectedTabClassName);
  }
}

TemplateEditor.SwitchTabClasses = function(selected, unselected, selectedTabClassName, unselectedTabClassName)
{
  TemplateEditor.SetTabClasses(selected, selectedTabClassName);
  TemplateEditor.SetTabClasses(unselected, unselectedTabClassName);
}

TemplateEditor.SetTabClasses = function(tabs, className)
{
  var tabLink;
  
  for (var tabIndex = 0; tabIndex < tabs.length; tabIndex++)
  {
    tabLink = document.getElementById(tabs[tabIndex]);
    
    if (tabLink) tabLink.className = className;
  }
}
